#include <bits/stdc++.h>
using namespace std;

const int N = 1e6;
int n, kc, kd;
int a[N], b[N], c[N], d[N];

struct Element {
    int time;
    int index;
} cc[N], dd[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        
        if(c[i] == 1 && d[i] == 1) {
            if(a[i] < b[i]) {
                kc++;
                cc[kc].time = a[i];
                cc[kc].index = i;
            } else {
                kd++;
                dd[kd].time = b[i];
                dd[kd].index = i;
            }
        }
        else if(c[i] == 1) {
            kc++;
            cc[kc].time = a[i];
            cc[kc].index = i;
        }
        else if(d[i] == 1) {
            kd++;
            dd[kd].time = b[i];
            dd[kd].index = i;
        }
    }
    
    sort(cc + 1, cc + kc + 1, [](const Element& x, const Element& y){
        return x.time < y.time;
    });
    sort(dd + 1, dd + kd + 1, [](const Element& x, const Element& y){
        return x.time < y.time;
    });
    
    cout << kc;
    for(int i = 1; i <= kc; i++){
        cout << " " << cc[i].index;
    }
    cout << '\n';
    
    cout << kd;
    for(int i = 1; i <= kd; i++) {
        cout << " " << dd[i].index;
    }
    cout << '\n';
    
    return 0;
}